home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_360 / uucp / uucp0.lzh / src / lib / getpwnam.c < prev    next >
C/C++ Source or Header  |  1990-04-04  |  2KB  |  112 lines

  1.  
  2. /*
  3.  *  GETPWNAM.C
  4.  *
  5.  *  $Header: Beta:src/uucp/src/lib/RCS/getpwnam.c,v 1.1 90/02/02 12:08:26 dillon Exp Locker: dillon $
  6.  *
  7.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  8.  *
  9.  *  (UUCP source support)
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <pwd.h>
  15. #include "config.h"
  16.  
  17. Prototype struct passwd *getpwnam(const char *);
  18.  
  19. Local char *Breakout(char **);
  20.  
  21. char *PasswdFile;
  22.  
  23. struct passwd *
  24. getpwnam(name)
  25. const char *name;
  26. {
  27.     FILE *fi;
  28.     char *buf = malloc(256);
  29.     static char User[32];
  30.     static char Passwd[32];
  31.     static char Dir[128];
  32.     static char Shell[256];
  33.     static struct passwd Pas = { User, Passwd, 0, 0, 0, "", "", Dir, Shell };
  34.  
  35.     if (PasswdFile)
  36.     fi = fopen(PasswdFile, "r");
  37.     else
  38.     fi = fopen(MakeConfigPath(UULIB, "Passwd"), "r");
  39.  
  40.     if (fi == NULL)
  41.     return(NULL);
  42.  
  43.     while (fgets(buf, 256, fi)) {
  44.     char *ptr = buf;
  45.     char *arg;
  46.  
  47.     arg = Breakout(&ptr);
  48.     if (strcmp(name, arg) != 0)
  49.         continue;
  50.     strcpy(Pas.pw_name, arg);
  51.     strcpy(Pas.pw_passwd, Breakout(&ptr));
  52.     Pas.pw_uid = atoi(Breakout(&ptr));
  53.     Pas.pw_gid = atoi(Breakout(&ptr));
  54.     Breakout(&ptr);     /*  finger info */
  55.     strcpy(Pas.pw_dir, Breakout(&ptr));
  56.     strcpy(Pas.pw_shell, Breakout(&ptr));
  57.  
  58.     {
  59.         short i = strlen(Pas.pw_dir) - 1;
  60.         if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
  61.         Pas.pw_dir[i++] = '/';
  62.         Pas.pw_dir[i] = 0;
  63.         }
  64.     }
  65.  
  66.     {
  67.         char *str;
  68.  
  69.         Pas.pw_shell_arg0 = Pas.pw_shell;
  70.         for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
  71.         if (*str) {
  72.         *str = 0;
  73.         ++str;
  74.         while (*str == ' ' || *str == 9)
  75.             ++str;
  76.         Pas.pw_shell_argn = str;
  77.         } else {
  78.         Pas.pw_shell_argn = str;
  79.         }
  80.     }
  81.  
  82.  
  83.     fclose(fi);
  84.     return(&Pas);
  85.     }
  86.     fclose(fi);
  87.     return(NULL);
  88. }
  89.  
  90. static
  91. char *
  92. Breakout(pptr)
  93. char **pptr;
  94. {
  95.     char *base;
  96.     char *ptr;
  97.  
  98.     base = *pptr;
  99.     if (base == NULL)
  100.     return("");
  101.     for (ptr = base; *ptr && *ptr != '\n' && *ptr != ','; ++ptr);
  102.     if (*ptr == ',') {
  103.     *pptr = ptr + 1;
  104.     *ptr = 0;
  105.     } else {
  106.     *pptr = NULL;
  107.     *ptr = 0;
  108.     }
  109.     return(base);
  110. }
  111.  
  112.